﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace VBAConvertor.Parsers
{
    public class ExitParser : ILineParser
    {
        public string Parse(Stack<ParseStatus> statuses, string lineContent, LinesReader reader, out bool success,
                            ref bool lineClosed)
        {
            success = lineContent.StartsWith("Exit") || lineContent.StartsWith("Next");
            if (!success) return lineContent;
            if (lineClosed)
            {
                throw new Exception();
            }
            lineClosed = true;
            var cs = statuses.Peek().CurrentState;
            switch (lineContent)
            {
                case "Exit":
                case "Exit Sub":
                case "Exit Function":
                    //if (statuses.c != State.FuncDef && cs != State.SubDef)
                    //{
                    //    throw new Exception();
                    //}
                    return "return;";
                case "Exit For":
                    
                    return "break;";
                case "Next For":
                    return "continue";
                default:
                    throw new NotImplementedException();
            }
        }
    }
}
